<h2>Marcador Final</h2>
<table class='score-header'>
	<t>
		<th>
		<?php echo $team_home_name;?>
		</th>
		<th>vs</th>
		<th>
		<?php echo $team_visit_name;?>
		</th>
		</tr>
		<tr>
			<td>
			<?php
			if(empty($home_score)) { echo 0;
			} else { echo $home_score;
			}
			?>
			</td>
			<td>-</td>
			<td>
			<?php
			if(empty($visit_score)) { echo 0;
			} else { echo $visit_score;
			}
			?>
			</td>
		</tr>
</table>

<table class='score-annotation'>
	<tr>
		<th colspan="2">
		<h1>Anotaciones</h1>
		</th>
	</tr>

	<?php
	
		$count = 0;
		$home_count = sizeof($annotations_home);
		$visit_count = sizeof($annotations_visit);
		//if ()
		//echo $home_count ."<br />";
		//echo $visit_count ."<br />";
		
		if ($home_count > $visit_count){
			$count = $home_count;
		} elseif ($visit_count > $home_count){
			$count = $visit_count;
		} elseif ($visit_count == $home_count){
			$count = $visit_count;
		}
	
		for($i = 0; $i <= $count -1; $i++) {
			
	?>
	<tr>
		<!-- TODO ADD link to playerinfo using id -->
		<td class='home'>
			<?php if(isset($annotations_home[$i]->player_name)){ ?>
				<span id="<?php echo $annotations_home[$i]->score_id ?>" class="delete-annotation-left ui-icon ui-icon-circle-close"></span>
				<a href="#"><?php echo $annotations_home[$i]->player_name ."</a> (".$annotations_home[$i]->time ."')"; }?>	
		</td>
		<td class='visit'>
		<?php if(isset($annotations_visit[$i]->player_name)){ ?>
				<span id="<?php echo $annotations_visit[$i]->score_id ?>" class="delete-annotation-right ui-icon ui-icon-circle-close"></span>
				<a href="#"><?php echo $annotations_visit[$i]->player_name ."</a> (".$annotations_visit[$i]->time ."')"; }?>
		</td>
	</tr>
	<?php
	}
	?>
</table>
<br />

<script>
	$('.delete-annotation-left').click( function() {
		//alert("delete player clicked");
		//alert("delete player clicked");
		var id_clicked = $(this).attr("id");
		//var team_id = $('#team_id').val();
		var $dialog = $('<div></div>')
		.html('Desea remover esta anotaci&oacute;n?')
		.dialog({
			autoOpen: false,
			title: 'Confirme operaci&oacute;n',
			buttons: {
				"Si": function() {
					$(this).dialog("close");
					//alert(id_clicked+"+"+$('#team_id').val());

					
					$.post("/index.php/matches/deleteScore", {
						'score_id' : id_clicked
					}, function() {

						$("#score-div").load("/index.php/matches/scorematchajax/<?php echo $match_id; ?>");

					});
					//alert("Jugadores Agregados!")
				},
				"No": function() {
					$(this).dialog("close");
				}
			}

		});

		$dialog.dialog('open');

		return false;
	});
	$('.delete-annotation-right').click( function() {
		//alert("delete player clicked");
		//alert("delete player clicked");
		var id_clicked = $(this).attr("id");
		//var team_id = $('#team_id').val();
		var $dialog = $('<div></div>')
		.html('Desea remover esta anotaci&oacute;n?')
		.dialog({
			autoOpen: false,
			title: 'Confirme operaci&oacute;n',
			buttons: {
				"Si": function() {
					$(this).dialog("close");
					//alert(id_clicked+"+"+$('#team_id').val());

					
					$.post("/index.php/matches/deleteScore", {
						'score_id' : id_clicked
					}, function() {

						$("#score-div").load("/index.php/matches/scorematchajax/<?php echo $match_id; ?>");

					});
					//alert("Jugadores Agregados!")
				},
				"No": function() {
					$(this).dialog("close");
				}
			}

		});

		$dialog.dialog('open');

		return false;
	});
</script>
